<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2023/9/6
  Time: 15:22
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<html>
<head>
    <title>MessageList</title>
    <link rel="stylesheet" href="/css/userlist.css">
</head>
<body>
<table border="1" cellspacing="0" align="center">
    <thead>
    <tr>
        <td>用户名</td>
        <td>真实姓名</td>
        <td>生日</td>
        <td>电话</td>
        <td>地址</td>
    </tr>
    </thead>
    <tbody>
    <c:forEach items="${users}" var="users">
        <tr>
            <td>${users.user_name}</td>
            <td>${users.real_name}</td>
            <td><fmt:formatDate value='${users.birthday}' pattern='yyyy-MM-dd' /></td>
            <td>${users.phone}</td>
            <td>${users.address}</td>
        </tr>
    </c:forEach>
    </tbody>
</table>
<div id="pagefy">
    <form action="${pageContext.request.contextPath }/userList" id="userForm">
        <input type="hidden" name="page" id="page" value="${page}">
        <input type="hidden" name="pageNumber" id="pageNumber" value="${pageNumber}">
        <a href="javascript:void(0)" onclick="submitMessageForm('first')">
            <button>首页</button>
        </a>
        <a href="javascript:void(0)" onclick="submitMessageForm('pre')">
            <button>上一页</button>
        </a>
        <span>${page} / ${pageNumber}</span>
        <a href="javascript:void(0)" onclick="submitMessageForm('next')">
            <button>下一页</button>
        </a>
        <a href="javascript:void(0)" onclick="submitMessageForm('last')">
            <button>尾页</button>
        </a>
    </form>
    <br>

</div>
</body>
<script>
    function submitMessageForm(flag){
        //获取当前页
        let c = Number(document.getElementById("page").value);
        if ("first" == flag){ //首页
            document.getElementById("page").value = 1;
        }else if ("pre" == flag){ //上一页
            if (c > 1){
                document.getElementById("page").value = c -1;
            }
        }else if ("next" == flag){
            //总页数
            let l = Number(document.getElementById("pageNumber").value);
            if (c < l){
                document.getElementById("page").value = c +1;
            }
        }else if ("last" == flag){
            document.getElementById("page").value = document.getElementById("pageNumber").value;
        }
        document.getElementById("userForm").submit();
    }
</script>
</html>
